#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

void solve() {
	string s; cin >> s;
	ll ans = 0;
	for (int i = 1; i < s.size(); i++) {
		if (s[i] == '_' && s[i - 1] == '_') {
			ans++;
		}
	}
	if (s[0] == '_') ans++;
	if (s[s.size() - 1] == '_') ans++;
	if (s.size() == 1 && s[0] == '^') ans++;
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int t; cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}